﻿using System;
using System.Diagnostics.Contracts;
using System.Linq;

namespace MathService.Statistic
{
    public static partial class Distributions
    {
        public static class Erlang
        {
            //public static double ModelA(double )

            private static double modelB_(double A, int N) { return Math.Pow(A, N) / N.Factorial(); }
            public static double ModelB(double A, int N, int n)
            {
                Contract.Requires(N > 0);
                Contract.Requires(n >= 0);
                return modelB_(A, N) / Enumerable.Range(0, N).Aggregate(0d, (S, i) => S + modelB_(A, i));
            }
            public static double ModelB(double A, int N) { return ModelB(A, N, N); }


            private static double modelC_(double A, int N) { return Math.Pow(A, N) * N / (N.Factorial() * (N - A)); }
            public static double ModelC_OC(double A, int N)
            {
                return 1 / (modelC_(A, N) + Enumerable.Range(0, N - 1).Aggregate(0d, (S, i) => modelB_(A, i)));
            }
            public static double ModelC(double A, int N) { return ModelC_OC(A, N) * modelC_(A, N); }
        }
    }
}
